﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：DataAccessDepartMent
// 文件功能描述：部门管理数据层
//
// 
// 创建标识：2012-01-13 周士祎
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;

namespace DAO.WaiGaoQiao
{
    public class DataAccessDepartMent
    {
        /// <summary>
        /// 获取所有部门信息
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllDepartment(string condition) 
        {
            sqldb db = new sqldb();
            string query = "select Dep_ID,Dep_No,DeptName,PriorNo,DeptLevel from FILE_DEPARTMENT where 1=1 "+condition;
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }
        /// <summary>
        /// 获取所有部门信息(分页）
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllDepartment(string Condition, int pagesize, int startindex)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select B.Dep_ID,B.Dep_No,B.DeptName,B.PriorNo,B.DeptLevel from (select ROW_NUMBER() OVER(ORDER BY A.Dep_ID DESC) rownumber,"
                             +"A.Dep_ID,A.Dep_No,A.DeptName,A.PriorNo,A.DeptLevel from FILE_DEPARTMENT A) B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString() + Condition;
                return db.ExecuteDataset(conn, CommandType.Text, query);
            }
        }
        /// <summary>
        /// 保存或修改部门信息
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveDepartMent(object[] dmpara)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                return db.ExecuteNonQuery(conn, "Proc_DepartMent", dmpara);
            }
        }
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteDepartMent(string did)
        {
            sqldb db = new sqldb();
            string query = "delete from FILE_DEPARTMENT where  Dep_ID = " + did;
            return db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
        }
        /// <summary>
        /// 部门数量合计
        /// </summary>
        /// <returns></returns>
        public int GetDepartCount(string Condition)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from FILE_DEPARTMENT where 1=1 " + Condition;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }
    }
}
